#pragma once

#include <AVUIAnimatable.h>

namespace AVUI {

class Renderer;
class Transform;

class Brush : public Animatable
{
public:
    DECLARE_ELEMENT(Brush, Animatable);

    virtual void set_ActiveBrush(Renderer* pRenderer) = 0;
    virtual void RenderDependencies(Renderer* pRenderer) { };
    virtual bool ContainsRenderDependencies() const { return false; };

    DECLARE_DEPENDENCY_PROPERTY(Transform);
    Transform* get_Transform() const { return m_pTransform; }
    void set_Transform(Transform* pTransform) { SetValue(get_TransformProperty(), (Object*)pTransform); } 

    DECLARE_DEPENDENCY_PROPERTY(RelativeTransform);
    Transform* get_RelativeTransform() const { return m_pRelativeTransform; }
    void set_RelativeTransform(Transform* pTransform) { SetValue(get_RelativeTransformProperty(), (Object*)pTransform); } 

    DECLARE_DEPENDENCY_PROPERTY(Opacity);
    float get_Opacity() const { return m_opacity; }
    void set_Opacity(float value) { SetValue(get_OpacityProperty(), BoxValue(value)); } 

    virtual void Precompute() { }
protected:
    Brush() : m_pTransform(NULL), m_pRelativeTransform(NULL), m_opacity(1.0f) { }
    virtual ~Brush() { }

private:
    static void StaticConstructor();
    static void TransformPropertyChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);
    static void RelativeTransformPropertyChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);
    static void OpacityPropertyChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);

    Transform* m_pTransform;
    Transform* m_pRelativeTransform;
    float m_opacity;

};

class BrushTypeConverter : public TypeConverter
{
    virtual bool CanConvertFrom(Object* pContext, const Type& type) const;
    virtual ObjectPtr ConvertFrom(Object* pContext, Object* pObjectFrom) const;
    virtual bool CanConvertTo(Object* pContext, const Type& type) const { return false; };
    virtual ObjectPtr ConvertTo(Object* pContext, Object* pObjectFrom, const Type& type) const { LibraryCriticalError(); return NULL; }
};



typedef TRefCountedPtr<Brush> BrushPtr;

}; // namespace AVUI
